<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	
class Pdf Extends MY_Controller
{
	private $__paid_fees;
	private $__all_fees;
	private $gperiods_value;
	private $student_name;
	private $student_idno;
	private $student_level;
	
	private $watermark_image;
	private $watermark_text;
	
	public function __construct()
	{
		parent::__construct();
		
		$this->load->library(array('mpdf'));
		$this->load->model('M_enrollees');
		$this->load->helper('misc');
		$this->gperiods_value	= $this->M_gperiods->get_current_gperiods_value('gp_desc');
		$this->student_name = $this->session->flashdata('student_name');
		$this->student_idno = $this->session->flashdata('student_idno');
		$this->student_level = $this->session->flashdata('student_level');
	}
	
	public function index()
	{
		show_404();
	}
	
	// class mPDF ([ string $mode [, mixed $format [, float $default_font_size [, string $default_font [, float $margin_left , float $margin_right , float $margin_top , float $margin_bottom , float $margin_header , float $margin_footer [, string $orientation ]]]]]])
	private function __create_pdf($html,$filename = FALSE,$footer = FALSE,$header = FALSE,$watermark = FALSE, $dimensions = FALSE, $orientation = "P")
	{
		set_time_limit(0);
		if($filename == FALSE)
		{
			$filename = str_replace(' ','_',trim($this->student_name)).'_'.trim($this->student_idno);
		}
		
		$now = date('F d, Y - h:i:s');
		
		if($dimensions == FALSE)
		{
			$mpdf=new mPDF('c','A4','','' , 10 , 10 , 10 , 10 , 5 , 5);
		}else{
			$s = $dimensions;

			if(is_array($s)){
				$size = isset($s[6]) ? [$s[6][0],$s[6][1]] :'A4';
				$mpdf=new mPDF('c',$size,'','' , $s[0] , $s[1] , $s[2] , $s[3] , $s[4] , $s[5], $orientation);
			}else{
				$size = $s;
				$mpdf=new mPDF('c',$size,'','');
			}
		}
		$mpdf->SetDisplayMode('fullpage');
		$mpdf->list_indent_first_level = 0;  // 1 or 0 - whether to indent the first level of a list
			if($footer !== FALSE)
			{
				if(is_bool($footer) === TRUE)
				{
					$mpdf->SetFooter('Page {PAGENO} of {nbpg} -  Generated At '.$now);
				}else{
					$mpdf->SetFooter($footer);
				}
			}
			
			if($header !== FALSE)
			{
				if(is_bool($header) === TRUE)
				{
					$mpdf->SetHeader($this->school_name);
				}else{
					$mpdf->SetHeader($header);
				}
			}
			
			if($watermark !== FALSE)
			{
				if($watermark == 'image')
				{
					$text = $this->watermark_image;
					$mpdf->SetWatermarkImage(school_logo(),0.2);
					$mpdf->showWatermarkImage = true;
				
				}elseif($watermark == 'text')
				{
					$text = $this->watermark_text;
					$mpdf->SetWatermarkText('DRAFT');
					$mpdf->showWatermarkText = true;
					$mpdf->watermarkImageAlpha = 0.1;
				}
			}
			
		$mpdf->SetDisplayMode('fullpage');
		$mpdf->WriteHTML($html);
		$mpdf->Output($filename,'I');
	}
	
	public function billing_form_print($id)
	{
		$x = $this->hs->decrypt($id);
		// pd($x);
		if($x)
		{
			$e_id = $x[0];
			$b_id = $x[1];
			
			$this->load->library('printer');
			$this->load->model('M_billing_form','mbf');
			$this->load->model('M_student','ms');
			
			$data['stud'] = $this->ms->get_student($e_id);
			$data['billings'] = $this->mbf->get_specific_bill($e_id,$b_id);
			$data['school_name'] = $this->school_name;
			$data['school_address'] = $this->school_address;
			
			$html = $this->load->view('legalforms/reminder',$data,TRUE);
			// echo $html;
			$fname = md5(time());
			set_time_limit(0);
			$this->printer->init('',array(254,190.5),'','',8,8,5,5)->generate($html,$fname);
		}else{
			show_error('Sorry. We cannot process your request. Broken Link Found.',404);
		}
	}

	/***** END LIBRARY REPORTS *****/
}